package fr.inria.zvtm.engine;

import java.util.Vector;

import fr.inria.zvtm.glyphs.Glyph;

public class Toolbar extends VirtualSpace {
	
	private double spacing = 50;

	private Toolbar(String n) {
		super(n);
	}
	
	public void addButton(Button b) {
		View view = getCamera(0).getOwningView();
		if (view != null) {
			double vx;
			double vy;
			double[] region = view.getVisibleRegion(getCamera(0));
			vy = region[1] - b.getHeight() / 2;
			if (getAllGlyphs().isEmpty()) {
				vx = region[0] + b.getWidth() / 2;
			} else {
				Glyph last = getAllGlyphs().lastElement();
				vx = last.getBounds()[2] + spacing;
			}
			b.moveTo(vx, vy);
		} 
		addGlyph(b);
	}
	
	public static Toolbar createNew(String name) {
        Toolbar toolbar = new Toolbar(name);
        VirtualSpaceManager.INSTANCE.allVirtualSpaces.put(name, toolbar);
        VirtualSpaceManager.INSTANCE.updateVirtualSpaceList();
        return toolbar;
	}


}
